﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace NEmu.MemoryPages
{
    public sealed class StructMemoryPage<TStruct> : MemoryPage where TStruct : struct
    {
        IntPtr m_StructPtr;

        public StructMemoryPage(IntPtr StructPtr)
        {
            m_StructPtr = StructPtr;
        }

        public override byte Read(ulong address)
        {
            return Marshal.ReadByte(m_StructPtr, (int)address);
        }

        public override void Write(ulong address, byte value)
        {
            Marshal.WriteByte(m_StructPtr, (int)address, value);
        }

        public override ulong Size
        {
            get { return (ulong)Marshal.SizeOf(typeof(TStruct)); }
        }

        public override void Clear()
        {
            for (int i = 0; i < (int)Size; i++)
            {
                Write((ulong)i, 0);
            }
        }

        public override void Dispose()
        {
           
        }
    }
}
